package com.ztgf.shopping.api.client.epg;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.shopping.models.bo.epg.EpgSectionCommodityRelationBO;
import com.ztgf.shopping.models.vo.epg.EpgSectionCommodityRelationVO;
import com.ztgf.shopping.models.vo.epg.EpgShopSectionCommodityRelationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.shopping.models.service.epg.IEpgShopSectionCommodityRelationService;
import com.ztgf.shopping.models.bo.epg.EpgShopSectionCommodityRelationBO;
import com.ztgf.shopping.models.dto.epg.EpgShopSectionCommodityRelationDTO;

import java.util.List;

/**
 * 店铺频道栏目商品表控制器
 *
 * @author YUE
 * @Date 2020-05-28 18:40:13
 */

@RestController
@RequestMapping("/api/epgShopSectionCommodityRelation")
@Slf4j
@Api(value = "EpgShopSectionCommodityRelationApiController",tags = "店铺频道栏目商品表Api接口")
public class EpgShopSectionCommodityRelationApiController {

    @DubboReference
    private IEpgShopSectionCommodityRelationService epgShopSectionCommodityRelationService;


    @ApiOperation(value = "频道栏目商品表",notes = "频道栏目商品表")
    @PostMapping("/getListBySectionId")
    public Result<List<EpgShopSectionCommodityRelationVO>> getListBySectionId(Long sectionId){
        EpgShopSectionCommodityRelationBO epgShopSectionCommodityRelationBO = new EpgShopSectionCommodityRelationBO();
        epgShopSectionCommodityRelationBO.setSectionId(sectionId);
        List<EpgShopSectionCommodityRelationVO> epgShopSectionCommodityRelationVOList = epgShopSectionCommodityRelationService.getListBySectionId(sectionId);
        return new Result<>(epgShopSectionCommodityRelationVOList);
    }


    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<EpgShopSectionCommodityRelationDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        EpgShopSectionCommodityRelationDTO dto = epgShopSectionCommodityRelationService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "店铺频道栏目商品表列表",notes = "店铺频道栏目商品表列表")
    @PostMapping("/queryPageList")
    public Result<Page<EpgShopSectionCommodityRelationDTO>> queryPageList(EpgShopSectionCommodityRelationBO bo){
       Wrapper<EpgShopSectionCommodityRelationDTO> wrapper = new EntityWrapper<>();
        if (bo.getStartDate() != null){
            wrapper.ge("create_time", bo.getStartDate());
        }
        if (bo.getEndDate() != null){
            wrapper.le("create_time", bo.getEndDate());

        }
        Page<EpgShopSectionCommodityRelationDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = epgShopSectionCommodityRelationService.selectPage(page, wrapper);

        return new Result<>(page);
    }
}
